package com.team.cluedo.app;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Vibrator;
import android.view.KeyEvent;
import android.widget.ImageView;
import android.widget.Toast;

import com.team.cluedo.Game;
import com.team.cluedo.R;
import com.team.cluedo.app.waitscreens.WaitForYourTurn;

public class ReceiveOneCard extends Activity {
	
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
	    setContentView(R.layout.receiveonecard);

	   
	    // vibration :
	    Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
	    int time = 1000; //(1sec)
	    vibrator.vibrate(time);

	    Toast.makeText(this, Game.cluedo.askedCard, Toast.LENGTH_SHORT).show();
	    
	    ImageView img = new ImageView(this);
	    img = (ImageView) findViewById(R.id.ImageViewViewCardPerso);
	    
	    Resources res = this.getResources();
	    Drawable myImage = res.getDrawable(toImageAdapter(Game.cluedo.askedCard));
	    img.setBackgroundDrawable(myImage);
	    

	}

	
	private Integer toImageAdapter(String cartes){
    	

    		if(cartes.equalsIgnoreCase("green")){
    			return  R.drawable.reverendgreen;
    		}
    		if(cartes.equalsIgnoreCase("mustard")){
    			return R.drawable.colonelmustard;
    		}
    		if(cartes.equalsIgnoreCase("scarlet")){
    			return (R.drawable.missscarlet);
    		}
    		if(cartes.equalsIgnoreCase("peacock")){
    			return (R.drawable.mrspeacock);
    		}
    		if(cartes.equalsIgnoreCase("white")){
    			return (R.drawable.mrswhite);
    		}
    		if(cartes.equalsIgnoreCase("plum")){
    			return (R.drawable.professorplum);
    		}
    		
    		
    		//Salle"hall","ballroom","conservatory","billard_room","library","study","lounge","dining_room","kitchen"
    		
    		if(cartes.equalsIgnoreCase("hall")){
    			return R.drawable.hall;
    		}
    		if(cartes.equalsIgnoreCase("ballroom")){
    			return  R.drawable.ballroom;
    		}
    		if(cartes.equalsIgnoreCase("conservatory")){
    			return (R.drawable.conversatory);
    		}
    		if(cartes.equalsIgnoreCase("billard_room")){
    			return (R.drawable.billardroom);
    		}
    		if(cartes.equalsIgnoreCase("study")){
    			return (R.drawable.study);
    		}
    		if(cartes.equalsIgnoreCase("lounge")){
    			return (R.drawable.lounge);
    		}
    		if(cartes.equalsIgnoreCase("dining_room")){
    			return (R.drawable.diningroom);
    		}
    		if(cartes.equalsIgnoreCase("kitchen")){
    			return (R.drawable.kitchen);
    		}
    		
    		
    		
    		//arme "candlestick","dagger","lead_pipe","revolver","rope","spanner"
    		
    		if(cartes.equalsIgnoreCase("candlestick")){
    			return R.drawable.candlestick;
    		}
    		if(cartes.equalsIgnoreCase("dagger")){
    			return R.drawable.dagger;
    		}
    		if(cartes.equalsIgnoreCase("lead_pipe")){
    			return (R.drawable.leadpipe);
    		}
    		if(cartes.equalsIgnoreCase("revolver")){
    			return (R.drawable.revolver);
    		}
    		if(cartes.equalsIgnoreCase("rope")){
    			return (R.drawable.rope);
    		}
    		if(cartes.equalsIgnoreCase("spanner")){
    			return (R.drawable.spanner);
    		}
    		return R.drawable.cover;
    }
	
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent msg) {
		if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
			Intent defineIntent;
			Game.cluedo.waitForFinishedTurn();
		}
	return false;
	}
}
